package webStudio7i.servlet;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import webStudio7i.excepcion.DAOExcepcion;
import webStudio7i.modelo.Instrumento;
import webStudio7i.modelo.Sala;
import webStudio7i.modelo.Servicio;
import webStudio7i.negocio.SalaBll;

/**
 * Servlet implementation class ArmadoSala
 */
public class ArmadoSala extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ArmadoSala() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String idSala = request.getParameter("idSala");
		//
		String[] colInstru = request.getParameterValues("colInstrumento");
		String[] colServ = request.getParameterValues("colServicio");
		//
		//String precio = request.getParameter("txtPrecioHora");
		//
		SalaBll bllSala = new SalaBll();
		//
		Sala oSala = new Sala(Integer.parseInt(idSala));
		//
		Collection<Servicio> colServicio = new ArrayList<Servicio>();
		for (String idservicio : colServ){
			Servicio oServ = new Servicio();
			oServ.setIdservicio(Integer.parseInt(idservicio));
			colServicio.add(oServ);
		}
		
		Collection<Instrumento> colInstrumento = new ArrayList<Instrumento>();
		for (String idinstrumento : colInstru){
			Instrumento oInst = new Instrumento();
			oInst.setIdinstrumento(Integer.parseInt(idinstrumento));
			colInstrumento.add(oInst);
		}
		
		try {
			bllSala.prepararSala(oSala, colInstrumento, colServicio);
			response.sendRedirect("busquedaSala.jsp");
		} catch (DAOExcepcion e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			System.out.println("Error durante armado");
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
